//
//  RequestArgument.m
//  lvfj
//
//  Created by lvfeijun on 2021/8/24.
//  Copyright © 2021 Goudu KuaiEx Technology(Shenzhen)Co.,ltd. All rights reserved.
//

#import "RequestArgument.h"
///猿题库
@implementation RequestArgument
// 表头 header
- (NSDictionary<NSString *,NSString *> *)requestHeaderFieldValueDictionary
{
    NSMutableDictionary *dict = [super requestHeaderFieldValueDictionary].mutableCopy;
    if ([GVUserDefaults standardUserDefaults].hq_token) {
        dict[@"jwt-token"] = [GVUserDefaults standardUserDefaults].hq_token;
    }
    return dict;
}
// 表单提交？？？
- (AFConstructingBlock)constructingBodyBlock
{
    if (_filePath) {
        return ^(id<AFMultipartFormData> formData) {
            NSData *data = [NSData dataWithContentsOfFile:self->_filePath];
            NSString *name = [[self->_filePath pathComponents] lastObject];
            NSString *formKey = @"file";
            NSString *type = @"application/zip";
            [formData appendPartWithFileData:data name:formKey fileName:name mimeType:type];
  
    };
    } else return nil;
    
}
/// 参数
- (id)requestArgument
{
    //form-data，authorIds：["197549826","151114753","151115503","11084875"]
    dic[@"authorIds"] = @"[197549826,151114753,151115503,11084875]";
    
    return _params;
}
// 参数区别
-(void)getArgument{
    NSMutableDictionary *dic = NSMutableDictionary.dictionary;
    NSArray *array = @[0,1,2,3,4];
    
    /**
     dic[@"ids"] = @[0,1,2,3,4];
     
     post：表单提交：的时候，会重排，顺序会变
     get：json提交：  的时候，转json字符串的时候，顺序就固定了
     ids[]:0
     ids[]:1
     ids[]:2
     ids[]:3
     ids[]:4
     */
    dic[@"ids"] = array;
    
    /**
     ids[0]:0
     ids[1]:1
     ids[2]:2
     ids[3]:3
     ids[4]:4
     
     @"ids[0]":0,
     @"ids[1]":1,
     @"ids[2]":2,
     @"ids[3]":3,
     @"ids[4]":4,
     */
    for (int i=0; i<array.count; i++) {
        NSString *key = [NSString stringWithFormat:@"ids[%d]",i];
        dic[key] = rray[i];
    }
    
    /**
     一般使用这种
     
     @"ids":@"0,1,2,3,4",
     */
    NSMutableString *mstr = NSMutableString.string;
    for (int i=0; i<array.count; i++) {
        [mstr appendFormat:@"%@,",array[i]];
    }
    dic[@"ids"] = mstr;
}

@end
